package com.kamistoat.meimeimall.meimeimallware.learn;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;

public class LearnApplicationRunListener implements SpringApplicationRunListener {
    private final SpringApplication application;
    private final String[] args;

    // SpringApplicationRunListener接口的实现类必须具有一个含有 SpringApplication application, String[] args参数的构造方法。
    public LearnApplicationRunListener(SpringApplication application, String[] args) {
        System.out.println("自定义运行时监听器--LearnApplicationRunListener被创建");
        this.application = application;
        this.args = args;
    }

    // 在running阶段抛出自定义Event
    @Override
    public void running(ConfigurableApplicationContext context) {
        System.out.println("自定义运行时监听器--LearnApplicationRunListener进入running阶段，抛出自定义Event");
        context.publishEvent(new LearnApplicationEvent(this, "自定义Event消息传递"));
    }
}
